package com.woniuxy.project115.kaer.commons.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.HashMap;

/**
 * @author HuH
 * @version 1.0
 * @CreatTime 2024-11-18 16:55
 * @description
 */

@Data
public class SMSUtil {
    private static String API = "https://106.ihuyi.com/webservice/sms.php?method=Submit";
    private static String ACCOUNT = "C13944563";
    private static String PASSWORD = "0c886fb9b520da30e65baea601411bf7";

    public static String sendCode(String mobile) throws Exception {
//        //使用hutool提供的Http工具发送请求
//        HashMap<String, Object> params = new HashMap<>();
//        params.put("account",ACCOUNT);
//        params.put("password",PASSWORD);
//        params.put("mobile",mobile);
//        params.put("format","json");
//        String code = String.valueOf((int)(Math.random()*9000)+1000);
//        System.out.println(code);
//        String content = "您的验证码是：" + code + "。请不要把验证码泄露给其他人。";
//        params.put("content",content);
//        //向第三方的接口发送请求
//        HttpResponse response = HttpRequest.post(API).form(params).execute();
//        String json = response.body();
//        String resultCode = JSONUtil.parseObj(json).get("code").toString();
//        if("2".equals(resultCode)){
//            return code;
//        }else{
//            throw new Exception("短信发送失败，错误状态码：" + resultCode);
//        }

        String code = String.valueOf((int)(Math.random()*9000)+1000);
        System.out.println(code);
        return code;
    }

    public static String sendCode(String mobile, String content) throws Exception {
//        //使用hutool提供的Http工具发送请求
//        HashMap<String, Object> params = new HashMap<>();
//        params.put("account",ACCOUNT);
//        params.put("password",PASSWORD);
//        params.put("mobile",mobile);
//        params.put("format","json");
//        String code = String.valueOf((int)(Math.random()*9000)+1000);
//        System.out.println(code);
//        params.put("content",content);
//        //向第三方的接口发送请求
//        HttpResponse response = HttpRequest.post(API).form(params).execute();
//        String json = response.body();
//        String resultCode = JSONUtil.parseObj(json).get("code").toString();
//        if("2".equals(resultCode)){
//            return code;
//        }else{
//            throw new Exception("短信发送失败，错误状态码：" + resultCode);
//        }

        String code = String.valueOf((int)(Math.random()*9000)+1000);
        System.out.println(code);
        return code;
    }
}
